<template>
  <a-form style="max-width: 550px" :model="formValue" :rules="rules" ref="formRef">
    <a-form-item label="发件人邮箱" name="originator">
      <a-input v-model="formValue.originator" placeholder="请输入发件人邮箱" />
    </a-form-item>

    <a-form-item label="SMTP地址">
      <a-input placeholder="请输入SMTP服务器地址" />
    </a-form-item>

    <a-form-item label="SMTP端口">
      <a-input placeholder="请输入SMTP服务器端口" />
    </a-form-item>

    <a-form-item label="SMTP用户名">
      <a-input placeholder="请输入SMTP用户名" />
    </a-form-item>

    <a-form-item label="SMTP密码">
      <a-input type="password" placeholder="请输入SMTP密码" />
    </a-form-item>

    <a-form-item label="邮件测试">
      <a-button>邮件测试</a-button>
    </a-form-item>

    <a-form-item :wrapperCol="{ offset: 5 }">
      <a-button type="primary" @click="formSubmit">更新邮件信息</a-button>
    </a-form-item>
  </a-form>
</template>

<script lang="ts">
  import { defineComponent, reactive, ref, toRefs } from 'vue';
  import { Message } from '@arco-design/web-vue';

  const rules = {
    originator: {
      required: true,
      message: '请输入发件人邮箱',
      trigger: 'blur',
    },
  };
  export default defineComponent({
    setup() {
      const formRef: any = ref(null);

      const state = reactive({
        formValue: {
          originator: '',
        },
      });

      function formSubmit() {
        formRef.value
          .validate()
          .then(() => {
            Message.success('验证成功');
          })
          .catch((error) => {
            console.log('error', error);
            Message.error('验证失败，请填写完整信息');
          });
      }

      return {
        formRef,
        ...toRefs(state),
        rules,
        formSubmit,
      };
    },
  });
</script>
